﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using THSERP.BaseProvider;
using THSLib;
using THSERP.BusinessEntities;
namespace THSERP.Modules.POS
{
    public partial class guiSelectPOSPrintList :THSERPScreen
    {
        public guiSelectPOSPrintList()
        {
            InitializeComponent();
            
        }

        private void guiSelectPOSPrintList_Load(object sender, EventArgs e)
        {
            if (THSApp.IsSynchronizeDatabase)
                fld_btnPrintList.Enabled = false;
            else
                fld_btnPrintList.Enabled = true;
            fld_dgcBRPOSs.Screen = this;
            fld_dgcBRPOSs.InitializeControl();
            fld_dteSearchFromBRPOSDate.Screen = this;
            fld_dteSearchToBRPOSDate.Screen = this;
            fld_dteSearchFromBRPOSDate.DateTime = THSApp.WorkingDate;
            fld_dteSearchToBRPOSDate.DateTime = THSApp.WorkingDate;
            //
            fld_lkeGEVATs.Screen = this;
            fld_lkeGEVATs.InitializeControl();
            POSEntities entity = (POSEntities)((BaseModuleERP)this.Module).CurrentModuleEntity;
            entity.lstBRPOSs.Invalidate(new DataSet());
            DataSet ds = new GEVATsController().GetAllObjects();

        }

        private void fld_btnSearch_Click(object sender, EventArgs e)
        {
            String strQuery = String.Format("SELECT * from BRPOSs WHERE (CONVERT(VARCHAR(10), [BRPOSDate], 112) >= CONVERT(VARCHAR(10),'{0}', 112)) AND (CONVERT(VARCHAR(10), [BRPOSDate], 112) <= CONVERT(VARCHAR(10),'{1}', 112)) AND ((FK_GEVATID IS NULL)OR (FK_GEVATID={2}))  AND AAStatus='Alive'",fld_dteSearchFromBRPOSDate.DateTime.ToString("yyyyMMdd"), fld_dteSearchToBRPOSDate.DateTime.ToString("yyyyMMdd"), Convert.ToInt32(fld_lkeGEVATs.EditValue));
            DataSet ds = new BRPOSsController().GetDataSet(strQuery);
            POSEntities entity = (POSEntities)((BaseModuleERP)this.Module).CurrentModuleEntity;
            entity.lstBRPOSs.Invalidate(ds);
            fld_dgcBRPOSs.RefreshDataSource();
            //fld_dgvBRPOSss.RefreshData();
            fld_chkSelectAllBRPOS.Checked = false;
        }

        private void fld_chkSelectAllBRPOS_CheckStateChanged(object sender, EventArgs e)
        {
            POSEntities entity = (POSEntities)((BaseModuleERP)this.Module).CurrentModuleEntity;
            if (Convert.ToBoolean(fld_chkSelectAllBRPOS.EditValue))
            {

                for (int i = 0; i < entity.BRPOSsList.Count; i++)
                {
                     ((BRPOSsInfo)entity.BRPOSsList[i]).AASelected=true;
                    //objBRPOSssInfo.AASelected = true;
                    //lst.Add(objBRPOSssInfo);
                }
            }
            else
            {
                for (int i = 0; i < entity.BRPOSsList.Count; i++)
                {
                    ((BRPOSsInfo)entity.BRPOSsList[i]).AASelected = false;
                    //BRPOSssInfo objBRPOSssInfo = ((BRPOSssInfo)entity.BRPOSssList[i]);
                    //objBRPOSssInfo.AASelected = false;
                    //lst.Add(objBRPOSssInfo);
                }
            }
            fld_dgvBRPOSs.RefreshData();
            fld_dgcBRPOSs.Views[0].RefreshData();
        }

        private void fld_btnPrintList_Click(object sender, EventArgs e)
        {
            POSEntities entity =(POSEntities)((BaseModuleERP)this.Module).CurrentModuleEntity;
            if (!entity.BRPOSsList.Exists("AASelected", true))
            {
                MessageBox.Show("Chưa chọn Bill!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }
    }
}